package com.ftg.learn;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.junit.Test;
import java.util.Arrays;

/**
 * @author Guo
 * @date 2022/3/7
 */
public class Generator {

    @Test
    public void generator(){

        String url = "jdbc:mysql://localhost:3306/busmanage";
        String username = "root";
        String password = "Gbtxspp7449";
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("lalala") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("E://workspace//javaspace//busManage//src//main//java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.ftg.learn") // 设置父包名
                            .moduleName("bus"); // 设置父包模块名
//                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D://workspace//project//busManage//src//main//java")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude(Arrays.asList("sys_user","sys_role","sys_user_role","sys_menu","sys_role_menu","sys_bus_info"
                            ,"sys_director","sys_bus_use_registration","sys_bus_expenditure","sys_approval","sys_log","sys_parameter")) // 设置需要生成的表名
                            .addTablePrefix("sys_"); // 设置过滤表前缀
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }

}
